name: Sync Version Packages PR
on:
  push:
    branches:
      - master

concurrency:
  group: sync-version-packages
  cancel-in-progress: true

jobs:
  create-release-pr:
    name: Create Changeset PR
    runs-on: ubuntu-latest
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
        with:
          egress-policy: audit

      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
        with:
          fetch-depth: 20000
          fetch-tags: true
          token: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
      - name: Install Dependencies
        run: yarn --immutable
      - name: Create Release Pull Request
        uses: backstage/changesets-action@99063c276a7f12e024cb310e7a05a3a5b89449f8 # v2.1.0
        with:
          # Calls out to `changeset version`, but also runs prettier
          version: yarn release
        env:
          GITHUB_TOKEN: ${{ secrets.GH_SERVICE_ACCOUNT_TOKEN }}
          HUSKY: '0'

      - name: Discord notification
        if: ${{ failure() }}
        uses: Ilshidur/action-discord@0c4b27844ba47cb1c7bee539c8eead5284ce9fa9 # 0.3.2
        env:
          DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
        with:
          args: 'Version Packages Sync Failed https://github.com/{{GITHUB_REPOSITORY}}/actions/runs/{{GITHUB_RUN_ID}}'
